package com.eling.elcms.system.model;

import com.eling.elcms.community.model.Building;
import com.eling.elcms.community.model.Community;
import com.eling.elcms.community.model.Department;
import com.eling.elcms.community.model.Organization;
import com.eling.elcms.privilege.model.User;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

import javax.persistence.*;
import java.util.Set;

/**
 * 用户
 * 
 * @author KEN
 *
 */
@Entity
@Indexed
public class ElcmsUser extends User {
    private static final long serialVersionUID = 7451872741091891482L;

    /** 所属机构 */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "pkOrganization")
    @IndexedEmbedded(depth = 1)
    private Organization organization;
    
    /** 所属社区 */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "pkCommunity")
    private Community community;
    
    /** 所属部门 */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "pkDepartment")
    private Department department;
    
	/** 是否校验用户登陆时的IP地址 */
	@Column
	private Boolean checkLoginIp;
	
	/** 职务 */
	@Column
	private String duty;
    
    /** 负责楼宇 */
    @ManyToMany
    @JoinTable(
            name = "sm_user_building",
            joinColumns = { @JoinColumn(name = "pkUser") },
            inverseJoinColumns = @JoinColumn(name = "pkBuilding")
    )
    @OrderBy("orderCode")
    private Set<Building> buildings;

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}
	
	public Community getCommunity() {
		return community;
	}

	public void setCommunity(Community community) {
		this.community = community;
	}
	
	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}
	
    public Set<Building> getBuildings() {
		return buildings;
	}

	public void setBuildings(Set<Building> buildings) {
		this.buildings = buildings;
	}

	public Boolean getCheckLoginIp() {
		return checkLoginIp;
	}

	public void setCheckLoginIp(Boolean checkLoginIp) {
		this.checkLoginIp = checkLoginIp;
	}

	public String getDuty() {
		return duty;
	}
	public void setDuty(String duty) {
		this.duty = duty;
	}
}
